﻿using System;
using System.Net;

namespace Hydra.Shell.ProjectionAttributes
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    public sealed class DataMemberAttribute : Attribute
    {
        private bool emitDefaultValue = true;
        private bool isNameSetExplicit;
        private bool isRequired;
        private string name;
        private int order = -1;

        public bool EmitDefaultValue
        {
            get
            {
                return this.emitDefaultValue;
            }
            set
            {
                this.emitDefaultValue = value;
            }
        }

        internal bool IsNameSetExplicit
        {
            get
            {
                return this.isNameSetExplicit;
            }
        }

        public bool IsRequired
        {
            get
            {
                return this.isRequired;
            }
            set
            {
                this.isRequired = value;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
                this.isNameSetExplicit = true;
            }
        }

        public int Order
        {
            get
            {
                return this.order;
            }
            set
            {
                if (value < 0)
                {
                    throw new Exception("OrderCannotBeNegative");
                }
                this.order = value;
            }
        }
    }
}
